<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		
		<title>全选例子</title>
	</head>
	<body>
		<form action="" method="post">
			<table border="1" cellspacing="0" cellpadding="10px">
				<tr><th></th> <th>姓名</th>   <th>性别</th>   <th>年龄</th>    <th>家庭住址</th></tr>
				<tr><td><input type="checkbox" name="studentfemale" id="" value="1" /></td>
							  <td>张三</td>   <td>女</td>     <td>19</td>     <td>福建省新罗区</td></tr>
				<tr><td><input type="checkbox" name="studentmale" id="" value="2" /></td>
							  <td>王五</td>   <td>男</td>     <td>20</td>     <td>福建省新罗区</td></tr>
				<tr><td><input type="checkbox" name="studentfemale" id="" value="3" /></td>
							  <td>赵六</td>   <td>女</td>     <td>18</td>     <td>福建省新罗区</td></tr>
				<tr><td><input type="checkbox" name="studentmale" id="" value="4" /></td>
							  <td>罗翔</td>   <td>男</td>     <td>17</td>     <td>福建省新罗区</td></tr>
				<tr><td><input type="checkbox" name="studentmale" id="" value="5" /></td>
							  <td>诸葛亮</td> <td>男</td>     <td>16</td>     <td>福建省新罗区</td></tr>
				<tr><td><input type="checkbox" name="studentfemale" id="" value="6" /></td>
							  <td>张亮</td>   <td>女</td>     <td>21</td>     <td>福建省新罗区</td></tr>
				<tr><td><input type="checkbox" name="studentfemale" id="" value="7" /></td>
							  <td>老王</td>   <td>女</td>     <td>14</td>     <td>福建省新罗区</td></tr>							
			</table>
			<td><input type="checkbox" name="" id="checkAllID" value="" onclick="checkAll();" /></td>全选
			<td><input type="checkbox" name="" id="checkAllmaleID" value="" onclick="checkAllmale()"/></td>男全选
			<td><input type="checkbox" name="" id="checkAllfemaleID" value="" onclick="checkAllfemale()"/></td>女全选
			<button type="submit">删除</button>
		</form>
		
	</body>
	<script type="text/javascript">
		function checkAll(){
			var tableObj = document.getElementById('tableId');
			var	allInput = document.getElementsByTagName('input');
			var checkAllDvalue = document.getElementById('checkAllID');
			
			for(var i=0; i<allInput.length;i++){
				allInput[i].checked = checkAllDvalue.checked;
			}
		}
		function checkAllmale(){
			            var Newman=document.getElementsByName('studentmale');
						console.log(Newman);
						//获取全选男按钮
						var allMan=document.getElementById('checkAllmaleID');
							
						//通过循环一起修改里面的checked
						for(var i=0;i<Newman.length;i++){
							Newman[i].checked=allMan.checked;
						}
		}
				function checkAllfemale(){
					//先获取为女的数组
					var NewWoman=document.getElementsByName('studentfemale');
					//获取全选女按钮
					var allWomen=document.getElementById('checkAllfemaleID');
						
					//通过循环一起修改里面的checked
					for(var i=0;i<NewWoman.length;i++){
						NewWoman[i].checked=allWomen.checked;
					}			
				}
	</script>
</html>
